﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    $(function () {
        gridList();
    })
    function gridList() {

        $('#dg').datagrid({
            url: "/DingTalkManage/Department/GetGridJson",
            toolbar: '#toolbar',
            autoRowHeight: false,
            nowrap: true,
            singleSelect: true,
            method: 'get',
            queryParams: {
                keyword: "",
            },
            columns: [[
                { field: 'Id', hidden: true },
                { field: 'Name', title: '部门名称', width: 150, align: 'center' },
                {
                    field: 'AutoAddUser', title: '是否自动入群', width: 150, align: 'center',
                    formatter: function (value, row, index) {
                        return value == true ? "<i class=\"fa fa-toggle-on\">是</i>" : "<i class=\"fa fa-toggle-off\">否</i>";
                    }
                },
                { field: 'OrgDeptOwner', title: '群主', width: 150, align: 'center' },
                {
                    field: 'UpdateTime', title: '登记时间', width: 130, align: 'right',
                    formatter: function (value, row, index) {
                        if (value) {
                            var time = new Date(value);
                            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate();
                        }
                    }
                }

            ]]
        });

        $("#btn_search").click(function () {
            var queryJson = {
                keyword: $("#txt_keyword").val()
            }
            $('#dg').datagrid('load', queryJson);
        });

    }
   
    function btn_details() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Details",
            title: "查看部门",
            url: "/DingTalkManage/Department/Details?keyValue=" + keyValue,
            width: "450px",
            height: "500px",
            btn: null,
        });
    }
    function btn_update() {
        $.submitPost({
            title: "确定要更新钉钉部门信息吗？",
            url: "/DingTalkManage/Department/UpdateDingTalkDepartment",
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>


<div class="gridPanel" style="height:100%;">
    <div id="toolbar" style="padding:2px 5px;">
        <div class="dcui-btn-area">
            <a href="#" id="NF-add" authorize="yes" class="dcui-btn dcui-btn-green" onclick="btn_add()"><i class="fa fa-plus"></i>新建部门</a>
            <a href="#" id="NF-delete" authorize="yes" class="dcui-btn dcui-btn-red" onclick="btn_delete()"><i class="fa fa-trash"></i>删除部门</a>
            <a href="#" id="NF-edit" authorize="yes" class="dcui-btn dcui-btn-blue" onclick="btn_edit()"><i class="fa fa-pencil"></i>修改部门</a>
            <a href="#" id="NF-details" authorize="yes" class="dcui-btn dcui-btn-purple" onclick="btn_details()"><i class="fa fa-eye"></i>查看部门</a>
            <a href="#" id="NF-update" authorize="yes" class="dcui-btn dcui-btn-orange" onclick="btn_update()"><i class="fa fa-reply"></i>更新数据</a>
        </div>
        <script>$('#toolbar').authorizeButton()</script>
        <div class="dcui-search-area">
            关键字: <input class="easyui-textbox" style="width:110px" id="txt_keyword" placeholder="用户名称/手机号码">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search">查询</a>
        </div>
    </div>

    <table id="dg" class="easyui-datagrid" style="width:100%;min-height:600px;height:100%;"></table>
</div>

